package com.example.netty.inoutbound.review2;

import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.ByteToMessageDecoder;

import java.util.List;

public class MyByteToIntegerDecoder extends ByteToMessageDecoder {
    @Override
    protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception {
        System.out.println("MyByteToIntegerDecoder 被调用");
        // 因为 int 4 个字节,需要判断 4 个字节，才能读取一个int
        if (in.readableBytes() >= 4) {
            out.add(in.readInt());
        }
    }
}
